<template>
    <div class="pages">
        <h2>骰子</h2>
        <p class="dice_item" v-for="i in 6" :key="i" @click="onModule(i)">{{ i }}点</p>
        <div class="content">
                ● flex-direction属性决定主轴的方向（即项目的排列方向）。<br>
                ● flex-wrap属性定义，如果一条轴线排不下，如何换行。<br>
                ● flex-flow属性是flex-direction属性和flex-wrap属性的简写形式，默认值为row nowrap。<br>
                ● justify-content属性定义了项目在主轴上的对齐方式。<br>
                ● align-items属性定义项目在交叉轴上如何对齐。<br>
                ● align-content属性定义了多根轴线的对齐方式。如果项目只有一根轴线，该属性不起作用。
        </div>
        
        <div class="model-bg" v-show="isDice" @click="onClosed">
            <div class="dice">
                <div :class="'dot_case dot_'+dot">
                    <template v-if="dot < 4">
                        <p class="dot" v-for="i in dot" :key="i"></p>
                    </template>
                    <template v-else-if="dot==4">
                        <div class="column">
                            <span class="dot"></span>
                            <span class="dot"></span>
                        </div>
                        <div class="column">
                            <span class="dot"></span>
                            <span class="dot"></span>
                        </div>
                    </template>
                    <template v-else-if="dot==5">
                        <div class="column">
                            <span class="dot"></span>
                            <span class="dot"></span>
                        </div>
                        <div class="column">
                            <span class="dot"></span>
                        </div>
                        <div class="column">
                            <span class="dot"></span>
                            <span class="dot"></span>
                        </div>
                    </template>
                    <template v-else>
                        <div class="column">
                            <span class="dot"></span>
                            <span class="dot"></span>
                            <span class="dot"></span>
                        </div>
                        <div class="column">
                            <span class="dot"></span>
                            <span class="dot"></span>
                            <span class="dot"></span>
                        </div>
                    </template>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
    data(){
        return {
            isDice: false,
            dot: 1,
        }
    },
    methods: {
        onModule(i: number) {
            console.log(i)
            this.dot = i
            this.isDice = true
        },
        onClosed(){
            this.isDice = false
        }
    }
})
</script>

<style scoped lang="less">
.pages {
    width: 100vw;
    height: 100vh;
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: flex-start;
}
.dice_item{
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 5px;
    width: 70vw;
    text-align: center;
    margin-top: 10px;
}
.model-bg{
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    .dice{
        width: 50vmin;
        height: 50vmin;
        background: white;
        border-radius: 10px;
        padding: 30px;
        box-shadow: inset 0 0 15px rgba(0,0,0,1);
    }
    .dot_case{
        display: flex;
        width: 100%;
        height: 100%;
        .dot{
            border-radius: 50px;
            background: #646cff;
            width: 30px;
            height: 30px;
        }
        .column{
            width: 50%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            .dot{
                border-radius: 50px;
                background: #646cff;
                width: 30px;
                height: 30px;
            }
        }
        &.dot_1{
            align-items: center;
            justify-content: center;
        }
        &.dot_2{
            flex-direction: column;
            justify-content: space-around;
            align-items: center;
        }
        &.dot_3{
            flex-direction: column;
            justify-content: space-around;
            align-items: center;
            .dot{
                &:first-child{
                    align-self: flex-start;
                }
                &:last-child{
                    align-self: flex-end;
                }
            }
        }
        &.dot_4{
            flex-direction: column;
            justify-content: space-around;
            align-items: center;
            flex-wrap: wrap;
            .column:last-child{
                align-items: flex-end;
            }
        }
        &.dot_5{
            flex-direction: column;
            justify-content: space-around;
            align-items: center;
            flex-wrap: wrap;
            .column{
                width: 30%;
                height: 100%;
                &:nth-child(2n) {
                    justify-content: center;
                }
            }
        }
    }
}
.content{
    font-size: 14px;
    //text-indent: 2em;
}
</style>